import { Link } from 'umi'
import {
  MenuOutlined, SettingOutlined, CommentOutlined,
  ReadOutlined, UserOutlined, SwitcherOutlined, InboxOutlined,
  HomeOutlined, EditOutlined, StarOutlined,
  DesktopOutlined, TeamOutlined, StockOutlined
} from '@ant-design/icons';
export const apiPrefix = "http://47.116.207.219:80/api";  //远程接口地址
//export const apiPrefix = "http://192.168.100.2:8080";  //远程接口地址

export const siteName = 'ZSDN - 知行交流社区';

export const baseUrl = '';

const filePrefix = apiPrefix + "/"


export function getFilePrefix() {
  return filePrefix;
}
export function setFilePrefix(filePath) {
  filePrefix = filePath;
}

export const getBase64 = (file) =>
  new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = (error) => reject(error);
  });

export function createHomeHeaderMenu(userType) {
  // userType: 0==管理员,1==普通用户
  let homeHeaderMenu = [
    {
      key: "homePage",
      label: <><HomeOutlined /> 首页</>
    },
    {
      key: "manageCenter",
      label: userType === 0 ? <><DesktopOutlined /> 管理中心</> : <><StockOutlined /> 创作者中心</>
    },
  ]

  if (userType !== 0) {
    homeHeaderMenu.splice(1, 0,
      {
        key: "article",
        label: <> <EditOutlined /> 发布文章</>
      },
      {
        key: "attentionList",
        label: <><TeamOutlined /> 关注列表</>
      },
      {
        key: "favorite",
        label: <><StarOutlined /> 收藏夹</>
      }
    );
  }


  return homeHeaderMenu;
}
export function createManageMenu(userType) {
  if (typeof (userType) !== 'number' || userType < 0 || userType > 1) {
    return null;
  }
  // userType: 0==管理员,1==普通用户
  let baseManageMenu = [
    {
      key: "commonManage",
      label: <><MenuOutlined /><span>内容管理</span></>,
      children: [
        {
          key: "articleManage",
          label: <Link to="/manageCenter/articleManage"><ReadOutlined />{userType === 0 ? <span>文章管理</span> : <span>我的文章</span>}</Link>
        },
        {
          key: "commentManage",
          label: <Link to="/manageCenter/commentManage"><CommentOutlined />{userType === 0 ? <span>评论管理</span> : <span>我的评论</span>}</Link>
        },
      ]
    },
  ]

  if (userType === 0) {
    baseManageMenu.unshift(
      {
        key: "userManage",
        label: <Link to="/manageCenter/userManage"><UserOutlined /><span>用户管理</span></Link>
      },
      {
        key: "classifyManage",
        label: <Link to="/manageCenter/classifyManage"><InboxOutlined /><span>分类管理</span></Link>
      },
      {
        key: "labelManage",
        label: <Link to="/manageCenter/labelManage"><SwitcherOutlined /><span>标签管理</span></Link>
      },
    )
  }

  if (userType === 1) {
    baseManageMenu.unshift(
      {
        key: "personalData",
        label: <Link to="/manageCenter/personalData"><UserOutlined /><span>个人资料</span></Link>
      },
      {
        key: "accountSetting",
        label: <Link to="/manageCenter/accountSetting"><SettingOutlined /><span>账号设置</span></Link>
      },
    )
  }

  return baseManageMenu;
}
